﻿using Microsoft.Extensions.DependencyInjection;

namespace Lightworks.Core.Cache
{
    public static class CacheExtensions
    {
        public static IServiceCollection UseCache(this IServiceCollection services, CacheConfig? config) 
        {
            if (config.UseRedis)
            {
                services.AddSingleton<ICacheService, RedisCacheService>(_ => {
                    return new RedisCacheService(config.RedisUrl);
                });
            }
            else 
            {
                services.AddSingleton<ICacheService, MemoryCacheService>();
            }
            return services;
        }
    }

    public class CacheConfig
    {
        public bool UseRedis { get; set; }
        public string RedisUrl { get; set; } = "127.0.0.1:6379";
    }
}
